package es.mgil.soaTest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import es.mgil.soaTest.utils.SoapProgressTask;

public class SoapMainActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */
	private static String ACTION_F2C = "http://tempuri.org/FahrenheitToCelsius";
	private static String ACTION_C2F = "http://tempuri.org/CelsiusToFahrenheit";
	private static String METHOD_F2C = "FahrenheitToCelsius";
	private static String METHOD_C2F = "CelsiusToFahrenheit";
	private static String PROPERTY_CELSIUS = "Celsius";
	private static String PROPERTY_FAHRENHEIT = "Fahrenheit";

	private Button btnFar, btnCel, btnClear;
	private EditText txtFar, txtCel;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.soap_main_layout);

		btnFar = (Button) findViewById(R.id.btnFar);
		btnCel = (Button) findViewById(R.id.btnCel);
		btnClear = (Button) findViewById(R.id.btnClear);
		txtFar = (EditText) findViewById(R.id.txtFar);
		txtCel = (EditText) findViewById(R.id.txtCel);

		btnFar.setOnClickListener(this);
		btnCel.setOnClickListener(this);
		btnClear.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case (R.id.btnFar):
			new SoapProgressTask(this, METHOD_F2C, PROPERTY_FAHRENHEIT, txtFar
					.getText().toString(), ACTION_F2C, txtCel).execute();
			break;
		case (R.id.btnCel):
			new SoapProgressTask(this, METHOD_C2F, PROPERTY_CELSIUS, txtCel
					.getText().toString(), ACTION_C2F, txtFar).execute();
			break;
		case (R.id.btnClear):
			txtCel.setText("");
			txtFar.setText("");
			break;
		}
	}
}